package com.mz.nhoz.xlsx;

import java.util.Iterator;
import java.util.LinkedHashMap;

public class XlsxTableHeaderMap extends LinkedHashMap<String, XlsxTableHeader> {
	private XlsxTableHeader[] headerArrray = null;
	public static final int HEADER_NOT_FOUND = -1;

	public XlsxTableHeader get(int headerIndex) {
		if (this.isEmpty()) {
			return null;
		}
		Iterator<XlsxTableHeader> iterator = this.values().iterator();

		XlsxTableHeader header = iterator.next();
		if (headerIndex == 0) {
			return header;
		}

		for (int i = 0; i < headerIndex; i++) {
			header = iterator.next();
		}

		return header;
	}

	public XlsxTableHeader get(String key) {
		return super.get(key);
	}

	/**
	 * Retorna el indice de un encabezado a partir del nombre del mismo.
	 * 
	 * @param headerName
	 * @return
	 */
	public int getHeaderIndex(String headerName) {
		Iterator<XlsxTableHeader> iterator = super.values().iterator();
		int i = 0;

		while (iterator.hasNext()) {
			XlsxTableHeader header = iterator.next();
			if (header.getName().contentEquals(headerName)) {
				return i;
			}

			i++;
		}

		return HEADER_NOT_FOUND;
	}

	public int getHeaderIndex(XlsxTableHeader header) {
		return this.getHeaderIndex(header.getName());
	}
}// XlsxTableHeaderMap
